package com.prothink.controller.statistics;


import com.prothink.entity.ProductSalesVolume;
import com.prothink.service.ProductSalesVolumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *商品销售控制层
 * @Date 2022 11 24
 */
@CrossOrigin
@Controller
@RequestMapping("ProductSalesVolume")
public class ProductSalesVolumeController {
    @Autowired
    private ProductSalesVolumeService productSalesVolumeService;

    /**
     * 获取全部被销售的商品
     * @param productSalesVolume 商品销售实体类
     * @return
     */
    @ResponseBody
    @RequestMapping("/getProductSalesVolume")
    public List getProductSalesVolume(ProductSalesVolume productSalesVolume){
        return productSalesVolumeService.getProductSalesVolume(productSalesVolume);
    }

    /**
     * 添加销售出去的商品信息
     * @param productSalesVolume 商品销售实体类
     * @return
     */
    @ResponseBody
    @RequestMapping("/addProductSalesVolume")
    public Integer addProductSalesVolume(ProductSalesVolume productSalesVolume){
        return productSalesVolumeService.addProductSalesVolume(productSalesVolume);
    }
    /**
     *
     * @param productSalesVolume 商品销售实体类
     * @return 近一个月或者近七天的数据
     */
    @ResponseBody
    @RequestMapping("/getProductSalesVolumeWeekandMod")
    public List getProductSalesVolumeWeekandMod(ProductSalesVolume productSalesVolume){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        try {
            Date parse = simpleDateFormat.parse(format);
            productSalesVolume.setSalesTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return productSalesVolumeService.getCourseWeekandModSalesVolume(productSalesVolume);
    }

    /**
     *
     * @param productSalesVolume 商品销售实体类
     * @return 上个月数据
     */
    @ResponseBody
    @RequestMapping("/getProductSalesVolumeOnMod")
    public List getProductSalesVolumesOnMod(ProductSalesVolume productSalesVolume){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        try {
            Date parse = simpleDateFormat.parse(format);
            productSalesVolume.setSalesTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return productSalesVolumeService.getProductOnModViews(productSalesVolume);
    }
    /**
     *
     * @param productSalesVolume 商品销售实体类
     * @return 上周数据
     */
    @ResponseBody
    @RequestMapping("/getProductSalesVolumeOnWeek")
    public List getProductSalesVolumeOnWeek(ProductSalesVolume productSalesVolume){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        try {
            Date parse = simpleDateFormat.parse(format);
            productSalesVolume.setSalesTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return productSalesVolumeService.getProductOnWeek(productSalesVolume);
    }

    /**
     *
     * @param productSalesVolume 商品销售实体类
     * @return 商品购买情况
     */
    @ResponseBody
    @RequestMapping("/getBuyProductSalesVolumeOnWeek")
    public List getBuyProductSalesVolumeOnWeek(ProductSalesVolume productSalesVolume){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        try {
            Date parse = simpleDateFormat.parse(format);
            productSalesVolume.setSalesTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return productSalesVolumeService.getBuyProductOnWeek(productSalesVolume);
    }
}
